package com.eques.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.eques.bean.WifiListBean;
import com.eques.demo.R;

import java.util.List;

public class WifiListAdapter extends BaseAdapter {

    private Context context;
    private List<WifiListBean> wifiListBeans;

    public WifiListAdapter(Context context, List<WifiListBean> wifiListBeans) {
        this.context = context;
        this.wifiListBeans = wifiListBeans;
    }

    @Override
    public int getCount() {
        return wifiListBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return wifiListBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
         view= LayoutInflater.from(context).inflate(R.layout.item_wifilist_name_layout,null);
        TextView tv_wifi_name=view.findViewById(R.id.tv_wifi_name);
        ImageView img_recommend=view.findViewById(R.id.img_recommend);
        ImageView img_wifi_rssi=view.findViewById(R.id.img_wifi_rssi);
        int db=wifiListBeans.get(i).getRssi();
        img_recommend.setVisibility(View.GONE);
        if(db>=-55){
            img_recommend.setVisibility(View.VISIBLE);
            img_wifi_rssi.setImageResource(R.mipmap.wifi_full_d);
        }else if(-70>=db && db<-55){
            img_wifi_rssi.setImageResource(R.mipmap.wifi3);
        }
        else if(-85>=db && db<-60){
            img_wifi_rssi.setImageResource(R.mipmap.wifi2);
        }
        else {
            img_wifi_rssi.setImageResource(R.mipmap.wifi1);
        }
        tv_wifi_name.setText(wifiListBeans.get(i).getSsid());
        return view;
    }
}
